<template>
  <div v-if="Object.keys(detailInfo).length !== 0" class="goods-list">
    <div class="info-desc clear-fix">
      <div class="desc">
        <div class="desc">{{detailInfo.desc}}</div>
      </div>
    </div>
    <div class="info-key">{{detailInfo.detailImage[0].key}}</div>
    <div class="info-list">
      <img
        v-for="(item, index) in detailInfo.detailImage[0].list"
        :key="index"
        :src="item"
        @load="imgLoad"
        alt
      />
    </div>
  </div>
</template>

<script>
export default {
  props: {
    detailInfo: {
      type: Object,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      counter: 0,
      imageLength: 0,
    }
  },
  methods: {
    imgLoad() {
      // 判断，所有的图片加载完成了之后，进行一次回调
      if (++this.counter === this.imageLength) {
        this.$emit('imageLoad')
      }
    },
  },
  watch: {
    detailInfo() {
      // 获取图片个数
      this.imageLength = this.detailInfo.detailImage[0].list.length
    },
  },
}
</script>

<style scoped>
.goods-list {
  padding: 30px 8px 0;
  border-bottom: 4px solid rgba(100, 100, 100, 0.1);
}
.info-desc {
  padding: 0 8px 0;
  font-size: 14px;
}
.info-desc .desc {
  text-indent: 2em;
}
.info-key {
  padding: 8px;
}
.info-list img {
  width: 100%;
}
</style>